package com.jboost.modules.app.controller;

import com.jboost.modules.system.mapper.LxPriceDataMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(tags = "客户管理")
@RestController
@RequestMapping("/wc")
@Slf4j
@AllArgsConstructor
public class WcController {


    StringRedisTemplate redisTemplate;
    LxPriceDataMapper lxPriceDataMapper;



    @GetMapping(value = "/gczx")
    @ApiOperation(value = "工厂做箱", notes = "工厂做箱")
    public List<List<String>> push1(@RequestParam(name = "msg",required = false) String msg) throws Exception {
        List<List<String>> newList = new ArrayList<>();
        List<Integer> indexs = Arrays.asList(1);
        String[] msgSplit = msg.split(",");
        List<List<String>> values = Arrays.stream(msgSplit).map(e -> Arrays.stream(e.split("\\｜")).collect(Collectors.toList())).collect(Collectors.toList());

        Map<String, List<List<String>>> listMap = values.stream()
                .collect(Collectors.groupingBy(s -> {
                    String key = "";
                    for (Integer index : indexs) {
                        key = key + s.get(index-1);
                    }
                    return key;
                }));
        listMap.values().forEach(e ->{
            newList.addAll(e);
            List<String> value = new ArrayList<>();
            value.add("");
            value.add("");
            value.add("");
            value.add("");
            value.add(String.valueOf(e.stream().mapToDouble(e1->Double.parseDouble(e1.get(4))).sum()));
            value.add(String.valueOf(e.stream().mapToDouble(e1->Double.parseDouble(e1.get(5))).sum()));
            value.add(String.valueOf(e.stream().mapToDouble(e1->Double.parseDouble(e1.get(6))).sum()));
            value.add("");
            newList.add(value);
        });
        return newList;
    }
}